{% extends "base.html" %}
{% load wiki_extras %}

{% block content %}
<script language="JavaScript" src="{{ MEDIA_URL }}js/jquery.min.js"></script>
<script language="JavaScript" src="{{ MEDIA_URL }}js/diff_match_patch.js"></script>
<script language="JavaScript" src="{{ MEDIA_URL }}js/render.js"></script>
<script language="JavaScript">//<![CDATA[
var dmp = new diff_match_patch();
var diff_visible = false;

function toggle_diff() {
  if(diff_visible) {
    close_diff();
    diff_visible = false;
  }
  else {
    view_diff();
    diff_visible = true;
  }
}

function view_diff() {
  var old_text = $('#old_text').val();
  var new_text = $('#new_text').val();
  var d = dmp.diff_main(old_text, new_text);
  dmp.diff_cleanupSemantic(d);
  var ds = dmp.diff_prettyHtml(d);
  $('#outputdiv').html(ds);
  $('#toggle_diff').val('Close diff');
}

function close_diff() {
  $('#outputdiv').html('');
  $('#toggle_diff').val('View diff to current');
}

//]]>
</script>
<table width="100%">
<tr>
<td><div id="page_body"></div><textarea id="page_text" style="display:none">{{ version.text }}</textarea></td><td style="text-align:right;vertical-align:top"><a href="{% url djambe.wiki.views.view page.id %}">Latest</a><br/><a href="{% url djambe.wiki.views.version_list page.id %}">History</a></td>
</tr>
<tr>
<td colspan="2" class="small">Author: {{ version.author }}</td>
</tr>
<tr>
<td colspan="2" class="small">Updated: {{ version.updated|date:"Y-m-d H:i" }}</td>
</tr>
</table>
<input type="button" onclick="location.href='{% url djambe.wiki.views.revert_version version.id %}'" value="Revert to this version" /><br/>
<input type="button" onclick="toggle_diff()" id="toggle_diff" value="View diff to current" />
<div id="outputdiv"></div><textarea id="old_text" style="display:none">{{ version.text }}</textarea><textarea id="new_text" style="display:none">{{ page.text }}</textarea>
<div id="root_url" style="display:none">{% url root %}</div>
{% endblock %}
